// 封装存储的工具
export const setStorage = (key, val) => {
  let value = "";
  if (typeof val === "object") {
    // 转换成字符串形式
    try {
      // 可能出错的代码
      value = JSON.stringify(val);
    } catch (e) {
      // 出现错误时执行
      console.log(e);
    }
  } else {
    value = val;
  }
  window.localStorage.setItem(key, value);
};
// getStorage("loginInfo");
export const getStorage = (key) => {
  let res = window.localStorage.getItem(key);
  if (res) {
    try {
      res = JSON.parse(res);
    } catch (e) {
      console.log(e);
    }
  }
  return res;
};

export const removeStorage = (key) => {
  window.localStorage.removeItem(key);
};
